
const express = require('express')
const initMiddleware = require('./middleware/index')
// const dbConnect = require('./utils/db')
const routes = require('./routes/index')
const logger = require('./utils/logger')
let createError = require('http-errors')     // 创建http错误,开发环境使用
const { initConfig } = require('./utils/fileDb')

const app = express()

// // 错误处理
// app.use('/', (req, res) => {
//   res.status(404).end("can not find " + req.path)
// })

initMiddleware(app)

const { port } = initConfig()


app.listen(port, async () => {
  logger.info(`server listening in http://127.0.0.1:${port}`)
  // dbConnect()
  routes(app)

  // app.use(function (req, res, next) {
  //   next(createError(404))
  // })
})
